package controller.Operation;

import util.BookDao;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 * @Question Insert
 * @Date 2022/12/18 12:22
 * @Solution
 */
public class Insert {
    public static void insertBook(JPanel Container, DefaultTableModel bookModel, JTable bookTable, JTextField bookID,
                           JTextField bookNAME, JTextField bookAUTHOR, JTextField bookPRESS) {
        String bookId=bookID.getText();
        String bookName=bookNAME.getText();
        String bookAuthor=bookAUTHOR.getText();
        String bookPress=bookPRESS.getText();
        if(bookId.equals("") || bookName.equals("") || bookAuthor.equals("") || bookAuthor.equals("")) {
            JOptionPane.showMessageDialog(Container, "左侧信息不能为空");
        }
        BookDao bookDao = new BookDao();
        if(bookDao.insert(bookId,bookName,bookAuthor,bookPress)==1) {
            JOptionPane.showMessageDialog(Container, "新增成功");
        }
        Show.showAllBook(bookModel);
    }
}
